package com.zg.job.quartz;

import com.zg.common.core.dao.system.SysJob;
import com.zg.common.core.util.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/3/5 18:52
 */
@Slf4j
@Service
public class CommonJobLauncher extends AJobLauncher {


    @Override
    public JobExecution executeBusinessLogic(JobLauncher jobLauncher, SysJob sysJob, JobParameters jobParameters) {
        JobExecution jobExecution = null;
        try {
//            Class clazz = Class.forName(sysJob.getClassPath());
//        sysJob.setJobClass(clazz);
            Job job =  SpringUtil.getBean(sysJob.getBeanName());

            jobExecution = jobLauncher.run(job, jobParameters);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return jobExecution;
    }


//    /**
//     * 是否是执行过的job
//     * 以下3个入参为唯一键
//     * @param taskName
//     * @param collateDate
//     * @param collateFile
//     * @return
//     */
//    private boolean isExecutedJob(String taskName, String collateDate, String collateFile) {
//        CollateRecord collateRecord = collateRecordMapper.getCollateRecord(taskName, collateDate, collateFile);
//        if (collateRecord == null) {
//            return false;
//        }
//        return true;
//    }


}
